package com.wans.guli.product.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

// import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.wans.guli.product.entity.SpuInfoEntity;
import com.wans.guli.product.vo.ProductSkuInfoRespVO;
import com.wans.guli.product.vo.ProductSkuInfoRestVO;
import com.wans.guli.product.vo.SkuInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.wans.guli.product.entity.SkuInfoEntity;
import com.wans.guli.product.service.SkuInfoService;
import com.wans.guli.common.utils.PageUtils;
import com.wans.guli.common.utils.R;


/**
 * sku信息
 *
 * @author wans
 * @email wansconst@163.com
 * @date 2025-08-01 15:14:35
 */
@RestController
@RequestMapping("product/skuinfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    @PostMapping("/listStock")
    public R listSock(@RequestBody List<ProductSkuInfoRestVO> productSkuInfoRestVOList) {
        List<ProductSkuInfoRespVO> data = skuInfoService.listSock(productSkuInfoRestVOList);

        return R.ok().put("data", data);
    }

    /**
     * 根据skuIds查询商品列表
     */
    @RequestMapping("/skuBySkuIds")
    public R list(@RequestParam("skuIds") List<Long> skuIds) {
        List<SkuInfoEntity> skuInfoEntities = skuInfoService.lambdaQuery()
                .in(SkuInfoEntity::getSkuId, skuIds)
                .list();

        return R.ok().put("data", skuInfoEntities);
    }

    /**
     * 列表
     */
    @GetMapping("/list")
    //@RequiresPermissions("product:skuinfo:list")
    public R list(SkuInfoVO skuInfoVO) {
        PageUtils page = skuInfoService.queryPage(skuInfoVO);

        return R.ok().put("page", page);
    }

    /**
     * 根据id查询信息
     */
    @GetMapping("/infoSku")
    public R infoById(@RequestParam("id") Long id) {
        SkuInfoEntity spuInfo = skuInfoService.getById(id);

        return R.ok().put("data", spuInfo);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{skuId}")
    //@RequiresPermissions("product:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId) {
        SkuInfoEntity skuInfo = skuInfoService.getById(skuId);

        return R.ok().put("skuInfo", skuInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("product:skuinfo:save")
    public R save(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.save(skuInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("product:skuinfo:update")
    public R update(@RequestBody SkuInfoEntity skuInfo) {
        skuInfoService.updateById(skuInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("product:skuinfo:delete")
    public R delete(@RequestBody Long[] skuIds) {
        skuInfoService.removeByIds(Arrays.asList(skuIds));

        return R.ok();
    }

}
